<?php 
include_once ('../../global.php');
$rd_id = $mt_round;
$show = $_GET['show'];
$cl_id =  $_GET['cls_id'];

$biaoji = isset($_GET['biaoji'])?$_GET['biaoji']:"";

?>

		
			
<?php
function toparcolor_mobile($score){
	if (!empty($score)){
		if ($score<='-2'){
            $color = 'mtwo';
        } else if ($score=='-1'){
            $color = 'mone';
        } else if ($score=='0'){
            $color = 'eng';
        } else if ($score=='1'){
            $color = 'pone';
        } else if ($score>='2'){
            $color = 'ptwo';
        } else {
            $color = 'eng';
        }
	} else {
		$color = 'eng';
	}
	return $color;
}


$start_hole = startHole($mt_id,$rd_id);
$holeScore   = getHoleScore($mt_id,$rd_id);        //当前洞和当前轮的topar
$score       = getScore($mt_id);                   //比赛成绩读取
for ($r=1;$r<=$rd_id;$r++){
    if (!empty($score['to_par'])){
        foreach ($score['to_par'] as $k => $v){
            $topar[$k] += $v[$r];
        }
    }
}

$groups = selGroupName($mt_id);
$navstrleaders = "";
$navstrhbh = "";
foreach($groups as $g=>$value  ){
	//print_r($value  );
	if($value['id']  == $cl_id || !$cl_id){
		$cl_id = $value['id'];
		if((strpos($value['name'],'B')!==false || strpos($value['name'],'C')!==false )&& $rd_id>2){
			$summarys[] = playerSummary($mt_id,2,$value['id']);       //循环得到数据
		}
		else{
			$summarys[] = playerSummary($mt_id,$rd_id,$value['id']);       //循环得到数据
		}
		$classname = ' class="selectedmenu" ';
		$tmgroupname = $value['name'];
		$leaderscolor =  "transparent";//"#000519";
	}
	else{
	  $classname = '';
	}
	$groupname = $lang == 'CN'?$value['name']:$value['name_en'];
	if($lang == 'CN'){
		$groupname = str_replace("A", '<font class="poppin" >A</font>', $groupname);
		$groupname = str_replace("B", '<font class="poppin" >B</font>', $groupname);
		$groupname = str_replace("C", '<font class="poppin" >C</font>', $groupname);
	}
	$groupclass=  $lang == 'CN'?'':'class = "poppin" ';
	$navstrleaders .='<div '.$classname.' onclick="gotocls(\''.$value['id'] .'\')" '.$groupclass.'>'.$groupname .'</div>';
	$navstrhbh .= 	'<div '.$classname.'  onclick="gotocls(\''.$value['id'] .'\')" '.$groupclass.'>'.$groupname .'</div>';
				
}

function getplayerphoto($plphoto){
	if($plphoto){
		return  $plphoto?('<img src="https://miniapp.scoringchina.com/admin/club/adm/images/players/'.$plphoto.'" class="plphoto"  />'):'';
	}
	else{
		return  '<img src="./images/player.png" class="plphoto"  />';
	}
	
}


function getplayername($players,$pl_id,$lang,$isshort=0){
	if($lang == 'CN'){
		if($players['playerEnshortName'][$pl_id]){
			return $players['playerEnshortName'][$pl_id];
		}
		else{
		return $players['playerName'][$pl_id];
		}
	}
	else{
		if($players['playerEnshortName'][$pl_id]){
			return $players['playerEnshortName'][$pl_id];
		}
		else{
			return $players['playerEnName'][$pl_id];
		}
	}
}



?>
	<?php  foreach($summarys as $s=>$value  ) {  
			 $tmgroupname = $groups[$s]['name'] ;
			//$leaderscolor = ((strpos($tmgroupname,'男')!==false) ? '#000519' :'#095557');
		
	?>
			<div class="groupcode">
				<?php echo $navstrleaders; ?>
			<?php
			 if($mt_round <1) 
			 {  
		        echo ' <div class="score_round" style=" float:right; margin-left:auto;margin-right:1%;width:auto;justify-content: center;display:flex; align-items:center;height:50px;">';
				
				for($i=1;$i<=$maxRound;$i++){
                	echo '<span class="jq_rclk"  style="float:right;width:30px;height:30px; border-radius:100%; margin-left:5px;margin-right:5px;display:flex;align-items:center;justify-content:center;'.(($i==$rd_id)?'background-color:#00438A;color:#fff;"':(($i<=$mt_round)?'background-color:#fff;color:#00438A;"':'background-color:#53565A;color:#fff;"')).'" onclick="changeround('.$i.')"> R'.$i.'</span>';//$roundtext[$i]
                }	
				
				
			   echo '</div>';
			 }
			?>
			</div>
			<table class="altrowstable scoringtable" id="scoringtable" >	
				<thead id="thhead" class="thead">
				<tr style="width:100%;">
					<!-- <th width="8%" style="color:#fff;">排名</th>
					<th width="33%" style="color:#fff;">球员</th>
					<th width="9%" style="color:#fff;">进程</th>
					<th width="10%"  style="color:#fff">成绩</th> -->
					<th class="<?php echo $css_class; ?>" width="8%"><?php echo t('pos'); ?></th>
        <th class="<?php echo $css_class; ?>" width="33%"><?php echo t('player'); ?></th>
        <th class="<?php echo $css_class; ?>" width="9%"><?php echo t('progress'); ?></th>
        <th class="<?php echo $css_class; ?>" width="10%"><?php echo t('score'); ?></th>
					<?php
					for($i=1;$i<=$maxRound;$i++){
                    	echo '<th width="10%" style="color:#fff" class="poppin">R'.$i.'</th>';
                    }	
					?>		
					<!-- <th width="10%"  style="color:#fff">总杆</th> -->
					<th class="<?php echo $css_class; ?>" width="10%"><?php echo t('total'); ?></th>
					
				</tr>






				
				</thead>
<tbody id="l<?php echo  $tmgroupname ; ?>">
<?php
$rank = $value['rank'];
$k=1;
$b=1;
if ($rank){
	foreach ($rank as $i => $n){
		echo '<tr '.(($k%2==0)?'class="oddrowcolor"':'').' style="width:100%;">
				<td width="8%"   class="poppin">'.((empty($n))?'-':$n).'</td>
				<td width="33%" align="left" style="text-align:left;display:flex;align-items:center;" class="pangmen">
					<a href="detail.php?mt_id='.$mt_id.'&pl_id='.$i.'&biaoji='.$biaoji.'"><div style="display:flex;align-items:center;">
					<span style="color:#fff;font-style:italic;display:none;">'.$players['playerCountry'][$i].'&nbsp;&nbsp;</span>'.getplayerphoto($players['pl_photo'][$i]).'<text style="width:90px;margin-left:5px;
					font-size: clamp(4px, 13px);
					max-width: 150px; /* 设置最大宽度 */
    overflow: hidden; /* 隐藏超出部分 */
    white-space: nowrap; /* 禁止换行 */
    
    transition: font-size 0.3s; /* 字体大小变化过渡效果 */
   " '.(($lang != 'CN' || $players['playerName'][$pl_id] == $players['playerEnName'][$pl_id])?'class="poppin" ':' ') .'>'.getplayername($players,$i,$lang,0).'</text>'.(($players['playerSex'][$i] == 0 && 1==0)?'&nbsp;
   <img src="./images/lady.png" width="10" height="10" style="padding-top:5px;padding-left:5px;" >':'').'</div></a>'.'
				</td>';
		if ($holeScore['thru'][$i]=='18'){
			if ($summary['checked'][$i]=='C'){
				echo '<td width="9%"  style="color:#fff;font-weight:bolder;" class="poppin"> F </td>';
			} else {
				echo '<td width="9%" > F </td>';
			}
		} else {
			if ($holeScore['thru'][$i]!=""){
				echo '<td width="9%" class="poppin">'.$holeScore['thru'][$i].' '.(($start_hole[$i] >= 10) ? '*':'').'</td>';
			} else {
			  echo '<td width="9%" class="poppin">-</td>';
			}
		}
				echo '<td width="10%" class="poppin" ><div class="topar '.(($topar[$i]<0)?'undereven"':(($topar[$i]==0)?'even"':(($topar[$i]>0)?'pluseven"':'"'))).'>'.(($topar[$i]=='0') ? 'E' : (($topar[$i]=='') ? '' : (($topar[$i]>0) ? '+'.$topar[$i] : $topar[$i]))).'</div></td>';
		
		$totalscore = 0;
		for($r=1;$r<=$maxRound;$r++){
			if($r<=$rd_id){
			if ($holeScore['thru'][$i]=='18' || $r<$mt_round){
			  echo '<td width="10%" class="poppin"><span '.(($score['to_par'][$i][$r]<0)?'style="color:#e50049;"':'').'>'.(($score['rd_score'][$i][$r])?$score['rd_score'][$i][$r]:'-').'</span></td>';
			}
			else{
			  echo '<td width="10%" class="poppin"><span '.(($score['to_par'][$i][$r]<0)?'style="color:#e50049;"':'').'>'.(($score['to_par'][$i][$r]=='0') ? 'E' : (($score['to_par'][$i][$r]=='') ? '' : (($score['to_par'][$i][$r]>0) ? '+'.$score['to_par'][$i][$r] : $score['to_par'][$i][$r]))).'</span></td>';
			}
			$totalscore +=$score['rd_score'][$i][$r];
			}
			else{
				echo '<td width="10%" class="poppin">-</td>';
			}
		}
		echo '<td width="10%" class="poppin">'.(($totalscore)?$totalscore:'-').'</td>';
		echo '</tr>';
		if ($k%10==0){
			if($b<=-1){
				echo '<tr><td colspan="8" style="background-color:transparent;"><img class="banner" src="./images/'.$b.'.gif" style="width:100%;height:auto" /></td></tr>';
			}
			
        
				$b++;
		}	
		$k++;
	}
}
?>				
				
				</tbody>
			</table>
	<?php }   ?>		
				
		

<--split-->

	<?php  foreach($summarys as $s=>$value  ) {  
			
			//$tmgroupname = $groups[$s]['name'] ;
			//$leaderscolor = ((strpos($tmgroupname,'男')!==false) ? '#000519' :'#095557');
		
	?>
			<div class="groupcode" id="con<?php echo  $tmgroupname ; ?>">
				<?php echo $navstrhbh; ?>
		<?php
			 if($mt_round >1) 
			 {  
		        echo ' <div class="score_round" style=" float:right; margin-left:auto;margin-right:1%;width:auto;justify-content: center;display:flex; align-items:center;height:50px;">';
				
				for($i=1;$i<=$maxRound;$i++){
                	echo '<span class="jq_rclk"  style="float:right;width:30px;height:30px; border-radius:100%; margin-left:5px;margin-right:5px;display:flex;align-items:center;justify-content:center;'.(($i==$rd_id)?'background-color:#00438A;color:#fff;"':(($i<=$mt_round)?'background-color:#fff;color:#00438A;"':'background-color:#53565A;color:#fff;"')).'" onclick="changeround('.$i.')"> R'.$i.'</span>';//$roundtext[$i]
                }	
				
				
			   echo '</div>';
			 }
			?>
			</div>

			<table class="altrowstable scoringtable" id="tbscoring<?php echo $s; ?>">
				<thead class="thead">
					<tr id="trHeader<?php echo $s; ?>">
						<th width="2%" rowspan="2" style="background-color:<?php echo  $leaderscolor ; ?>;color:#fff"> Pos </th>
						<th width="20%" rowspan="2" style="background-color:<?php echo  $leaderscolor ; ?>;color:#fff"> Players-<?php echo  $tmgroupname ; ?></th>
						<th width="3%" rowspan="2" style="background-color:<?php echo  $leaderscolor ; ?>;color:#fff"> After </th>
						<th width="4%" rowspan="2" style="background-color:<?php echo  $leaderscolor ; ?>;color:#fff"> TP </th>
						<th width="4%" rowspan="2" style="background-color:<?php echo  $leaderscolor ; ?>;color:#fff"> TD </th>
						<th width="2%" style="background-color:<?php echo  $leaderscolor ; ?>;color:#fff">1</th>
						<th width="2%" style="background-color:<?php echo  $leaderscolor ; ?>;color:#fff">2</th>
						<th width="2%" style="background-color:<?php echo  $leaderscolor ; ?>;color:#fff">3</th>
						<th width="2%" style="background-color:<?php echo  $leaderscolor ; ?>;color:#fff">4</th>
						<th width="2%" style="background-color:<?php echo  $leaderscolor ; ?>;color:#fff">5</th>
						<th width="2%" style="background-color:<?php echo  $leaderscolor ; ?>;color:#fff">6</th>
						<th width="2%" style="background-color:<?php echo  $leaderscolor ; ?>;color:#fff">7</th>
						<th width="2%" style="background-color:<?php echo  $leaderscolor ; ?>;color:#fff">8</th>
						<th width="2%" style="background-color:<?php echo  $leaderscolor ; ?>;color:#fff">9</th>
						<th width="3%" style="background-color:<?php echo  $leaderscolor ; ?>;color:#fff">OUT</th>
						<th width="2%" style="background-color:<?php echo  $leaderscolor ; ?>;color:#fff">10</th>
						<th width="2%" style="background-color:<?php echo  $leaderscolor ; ?>;color:#fff">11</th>
						<th width="2%" style="background-color:<?php echo  $leaderscolor ; ?>;color:#fff">12</th>
						<th width="2%" style="background-color:<?php echo  $leaderscolor ; ?>;color:#fff">13</th>
						<th width="2%" style="background-color:<?php echo  $leaderscolor ; ?>;color:#fff">14</th>
						<th width="2%" style="background-color:<?php echo  $leaderscolor ; ?>;color:#fff">15</th>
						<th width="2%" style="background-color:<?php echo  $leaderscolor ; ?>;color:#fff">16</th>
						<th width="2%" style="background-color:<?php echo  $leaderscolor ; ?>;color:#fff">17</th>
						<th width="2%" style="background-color:<?php echo  $leaderscolor ; ?>;color:#fff">18</th>
						<th width="3%" style="background-color:<?php echo  $leaderscolor ; ?>;color:#fff">IN</th>
						<?php
						for($i=1;$i<=$maxRound;$i++){
							echo '<th width="3%" rowspan="2" style="background-color:'. $leaderscolor .';color:#fff">R'.$i.'</th>';
						}
						?>
						<th width="3%" rowspan="2" style="background-color:<?php echo  $leaderscolor ; ?>;color:#fff"> Total </th>
					</tr>
					<tr id="trHeader<?php echo $s; ?>">
						<?php
                            $out_total = $in_total = 0;
                            for ($i=1;$i<10;$i++){
                                echo '<th class="clspar" style="background-color:'. $leaderscolor .';color:#fff">'.$pars["par"][$cl_id][($i-1)].'</th>';
                                $out_total += $pars["par"][$cl_id][($i-1)];
                            }
                            echo '<th class="clspar" style="background-color:'. $leaderscolor .';color:#fff">'.$out_total.'</th>';

                            for ($i=10;$i<19;$i++){
                                echo '<th class="clspar" style="background-color:'. $leaderscolor .';color:#fff">'.$pars["par"][$cl_id][($i-1)].'</th>';
                                $in_total += $pars["par"][$cl_id][($i-1)];
                            }
                            echo '<th class="clspar" style="background-color:'. $leaderscolor .';color:#fff">'.$in_total.'</th>';
                        ?>
					</tr>
					</thead>
					<tbody>
<?php
$k=1;
$rank_hbh = $value['rank'];
if ($rank_hbh){
foreach ($rank_hbh as $i => $n){
	echo '<tr '.(($k%2==0)?'class="oddrowcolor"':'').'>
			<td>'.((empty($n))?'-':$n).'</td>
			<td style="text-align:left;">
			<span style="color:'.$leaderscolor.';font-style:italic">'.$players['playerCountry'][$i].'</span>&nbsp;&nbsp;'.getplayername($players,$i,$lang,0).
			(($players['playerSex'][$i] == 0)?'&nbsp;<img src="./images/lady.png" width="10" height="10" style="padding-top:5px;padding-left:5px;" >':'').'</td>';
	//完成洞数
    if ($holeScore['thru'][$i]=='18'){
        if ($summary['checked'][$i]=='C'){
            echo '<td> F </td>';
        } else {
            echo '<td> F </td>';
        }
    } else {
        if ($holeScore['thru'][$i]!=""){
            echo '<td>'.$holeScore['thru'][$i].' '.(($start_hole[$i] == 10) ? '*':'').'</td>';
        } else {
          echo '<td></td>';
        }
    }
   echo '<td ><div class="topar '.(($topar[$i]<0)?'undereven"':(($topar[$i]==0)?'even"':(($topar[$i]>0)?'pluseven"':'"'))).'>'.(($topar[$i]=='0') ? 'E' : (($topar[$i]=='') ? '' : (($topar[$i]>0) ? '+'.$topar[$i] : $topar[$i]))).'</div></td>';
	echo	  '<td '.(($score['to_par'][$i][$rd_id]<0)?'style="color:#e50049;"':'').'>'.(($score['to_par'][$i][$rd_id]=='0') ? 'E' : (($score['to_par'][$i][$rd_id]=='') ? '' : (($score['to_par'][$i][$rd_id]>0) ? '+'.$score['to_par'][$i][$rd_id] : $score['to_par'][$i][$rd_id]))).'</td>';
	//18洞成绩
    $out_score = $in_score = 0;
    for ($h=1;$h<10;$h++){
        echo '<td class="'.toparcolor_mobile($holeScore['topar'][$i][$h]).'">'.$holeScore['score'][$i][$h].'</td>';
        $out_score += $holeScore['score'][$i][$h];
    }
    echo '<td class="inout">'.$out_score.'</td>';
    for ($h=10;$h<19;$h++){
        echo '<td class="'.toparcolor_mobile($holeScore['topar'][$i][$h]).'">'.$holeScore['score'][$i][$h].'</td>';
        $in_score += $holeScore['score'][$i][$h];
    }
    echo '<td class="inout">'.$in_score.'</td>';

    //R1-R4成绩
    $totalscore = '';
    for($r=1;$r<=$maxRound;$r++){
        if ($r<=$rd_id){
            echo '<td  style="background-color:'.$leaderscolor.';color:#fff">'.$score['rd_score'][$i][$r].'</td>';
            $totalscore += $score['rd_score'][$i][$r];
        } else {
            echo '<td style="background-color:'.$leaderscolor.';color:#fff">-</td>';
        }
    }
    echo '<td class="inout">'.$totalscore.'</td>';
	echo '</tr>';
	$k++;
	}
}
?>
		<!--	<tr ><td colspan="30" style="text-align:center;background-color:white;"><img class="banner" src="./images/1-1.png"></td></tr>-->
				</tbody>
			</table>

			<?php }   ?>	
			
			


		



